﻿using System;
using System.Drawing;
using System.ComponentModel.Composition;

namespace RDPAddins.Common
{
    /// <summary>
    /// Provides addin's metadata
    /// </summary>
    public interface IAddinMetadata
    {
        /// <summary>
        /// Gets addin name
        /// </summary>
        string AddinName { get; }

        /// <summary>
        /// Get addin channel name
        /// </summary>
        string ChannelName { get; }

        /// <summary>
        /// Gets channel options
        /// </summary>
        ChannelOptions ChannelOptions { get; }
    }

    /// <summary>
    /// Inherited from System.ComponentModel.Composition.ExportAttribute.
    /// Every addins should have one as an addin description.
    /// </summary>
    [MetadataAttribute]
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
    public class AddinMetadataAttribute : ExportAttribute
    {
        /// <summary>
        /// Initializes a new instance of the AddinMetadataAttribute class, exporting the type or member marked with this attribute with the specified name, channel name and channel options.
        /// </summary>
        /// <param name="AddinName">Name of the addin.</param>
        /// <param name="ChannelName">!!! should be less than 7 chars !!! Channel name.</param>
        /// <param name="ChannelOptions">Specified channel's options</param>
        public AddinMetadataAttribute(string AddinName, string ChannelName, ChannelOptions ChannelOptions)
            : base(typeof(IAddin))
        {
            this.AddinName = AddinName;
            this.ChannelName = ChannelName;
            this.ChannelOptions = ChannelOptions;
        }

        /// <summary>
        /// Gets addin name
        /// </summary>
        public string AddinName { get; private set; }

        /// <summary>
        /// Get addin channel name
        /// </summary>
        public string ChannelName { get; private set; }

        /// <summary>
        /// Gets channel options
        /// </summary>
        public ChannelOptions ChannelOptions { get; private set; }
    }

    /// <summary>
    /// Specifies the options for this virtual channel.
    /// </summary>
    [Flags]
    public enum ChannelOptions : uint
    {
        /// <summary>
        /// The channel is initialized.
        /// </summary>
        Initialized = 0x80000000,
        /// <summary>
        /// Encrypt client-to-server data.
        /// </summary>
        EncryptRDP = 0x40000000,
        /// <summary>
        /// Encrypt server-to-client data.
        /// </summary>
        EncryptSC = 0x20000000,
        /// <summary>
        /// Encrypt client-to-server data.
        /// </summary>
        EncryptCS = 0x10000000,
        /// <summary>
        /// Channel data should be sent with high Multipoint Communications Services (MCS) priority.
        /// </summary>
        PriorityHigh = 0x08000000,
        /// <summary>
        /// Channel data should be sent with medium MCS priority.
        /// </summary>
        PriorityMedium = 0x04000000,
        /// <summary>
        /// Channel data should be sent with low MCS priority.
        /// </summary>
        PriorityLow = 0x02000000,
        /// <summary>
        /// Virtual channel data should be compressed if RDP data is being compressed.
        /// </summary>
        CompressRDP = 0x00800000,
        /// <summary>
        /// Virtual channel data should be compressed, regardless of Remote Desktop Protocol (RDP) compression.
        /// </summary>
        Compress = 0x00400000,
        /// <summary>
        /// Affects how data sent by the IChannel.Write function is received at the server end. If this value is set, each data block is preceded by a CHANNEL_PDU_HEADER structure. If this value is not set, the data block includes only the data specified to IChannel.Write.
        /// </summary>
        ShowProtocol = 0x00200000
    }
}
